<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式匹配 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            color: #d4d4d4;
            line-height: 1.6;
        }
        .keyword { color: #c586c0; }
        .function { color: #dcdcaa; }
        .string { color: #ce9178; }
        .number { color: #b5cea8; }
        .comment { color: #6a9955; }
        .operator { color: #d4d4d4; }
        .builtin { color: #4ec9b0; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.1rem;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
        .section-divider {
            position: relative;
            text-align: center;
            margin: 3rem 0;
        }
        .section-divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
        }
        .section-divider span {
            background: white;
            padding: 0 1.5rem;
            position: relative;
            color: #9ca3af;
            font-size: 0.875rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">正则表达式匹配</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">探索动态规划的优雅解法</p>
            <div class="flex justify-center gap-6 text-sm">
                <span class="flex items-center gap-2">
                    <i class="fas fa-code"></i>
                    <span>算法设计</span>
                </span>
                <span class="flex items-center gap-2">
                    <i class="fas fa-brain"></i>
                    <span>动态规划</span>
                </span>
                <span class="flex items-center gap-2">
                    <i class="fas fa-clock"></i>
                    <span>O(m×n)</span>
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.2s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 flex items-center gap-3">
                    <i class="fas fa-puzzle-piece text-purple-600"></i>
                    <span>题目描述</span>
                </h2>
                <div class="prose prose-lg max-w-none">
                    <p class="text-gray-700 leading-relaxed">
                        <span class="drop-cap serif-font">给</span>定一个字符串 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">s</code> 和一个字符模式 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">p</code>，实现支持 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">.</code> 和 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">*</code> 的正则表达式匹配。
                    </p>
                    <div class="grid md:grid-cols-2 gap-6 mt-6">
                        <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                            <h3 class="font-semibold text-lg mb-3 flex items-center gap-2">
                                <i class="fas fa-dot-circle text-purple-600"></i>
                                点号匹配
                            </h3>
                            <p class="text-gray-700"><code class="bg-white px-2 py-1 rounded">.</code> 匹配任意单个字符</p>
                        </div>
                        <div class="bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-xl">
                            <h3 class="font-semibold text-lg mb-3 flex items-center gap-2">
                                <i class="fas fa-asterisk text-blue-600"></i>
                                星号匹配
                            </h3>
                            <p class="text-gray-700"><code class="bg-white px-2 py-1 rounded">*</code> 匹配零个或多个前面的元素</p>
                        </div>
                    </div>
                    <div class="mt-6 p-4 bg-yellow-50 border-l-4 border-yellow-400 rounded">
                        <p class="text-gray-700">
                            <i class="fas fa-exclamation-triangle text-yellow-600 mr-2"></i>
                            <strong>注意：</strong>匹配应覆盖整个字符串（不是部分匹配）
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.3s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 flex items-center gap-3">
                    <i class="fas fa-lightbulb text-yellow-500"></i>
                    <span>核心考点</span>
                </h2>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="text-center p-6 bg-gradient-to-br from-purple-100 to-purple-50 rounded-xl">
                        <i class="fas fa-table text-4xl text-purple-600 mb-4"></i>
                        <h3 class="font-semibold text-xl mb-2">动态规划</h3>
                        <p class="text-gray-600">构建状态转移表，优化时间复杂度</p>
                    </div>
                    <div class="text-center p-6 bg-gradient-to-br from-blue-100 to-blue-50 rounded-xl">
                        <i class="fas fa-undo text-4xl text-blue-600 mb-4"></i>
                        <h3 class="font-semibold text-xl mb-2">回溯算法</h3>
                        <p class="text-gray-600">递归探索所有可能的匹配路径</p>
                    </div>
                    <div class="text-center p-6 bg-gradient-to-br from-green-100 to-green-50 rounded-xl">
                        <i class="fas fa-sitemap text-4xl text-green-600 mb-4"></i>
                        <h3 class="font-semibold text-xl mb-2">状态转移</h3>
                        <p class="text-gray-600">精确定义状态间的转换关系</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.4s;">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-6 flex items-center gap-3">
                    <i class="fas fa-project-diagram text-green-600"></i>
                    <span>算法流程图</span>
                </h2>
                <div class="mermaid">
                    graph TD
                        A[开始匹配] --> B{检查当前字符}
                        B -->|普通字符| C[直接比较]
                        B -->|点号 .| D[匹配任意字符]
                        B -->|星号 *| E[处理零个或多个]
                        
                        C --> F{是否匹配}
                        D --> F
                        E --> G{匹配零个}
                        E --> H{匹配多个}
                        
                        F -->|是| I[继续下一位]
                        F -->|否| J[返回 False]
                        G --> I
                        H --> I
                        
                        I --> K{是否结束}
                        K -->|否| B
                        K -->|是| L[返回结果]
                        
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style L fill:#27c93f,stroke:#fff,color:#fff
                        style J fill:#ff5f56,stroke:#fff,color:#fff
                </div>
            </div>
        </section>

        <!-- Solution Approach -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.5s;">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-6 flex items-center gap-3">
                    <i class="fas fa-route text-indigo-600"></i>
                    <span>解题思路</span>
                </h2>
                
                <!-- Dynamic Programming Approach -->
                <div class="mb-8">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center gap-2">
                        <span class="bg-purple-600 text-white w-8 h-8 rounded-full flex items-center justify-center text-sm">1</span>
                        动态规划法
                    </h3>
                    <div class="bg-gradient-to-r from-purple-50 to-pink-50 p-6 rounded-xl mb-4">
                        <p class="text-gray-700 mb-4">
                            定义 <code class="bg-white px-2 py-1 rounded font-mono">dp[i][j]</code> 表示字符串 <code class="bg-white px-2 py-1 rounded font-mono">s[0:i]</code> 和模式 <code class="bg-white px-2 py-1 rounded font-mono">p[0:j]</code> 是否匹配
                        </p>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="bg-white p-4 rounded-lg">
                                <h4 class="font-semibold mb-2 text-purple-700">
                                    <i class="fas fa-clock mr-2"></i>时间复杂度
                                </h4>
                                <p class="text-2xl font-mono text-gray-800">O(m × n)</p>
                            </div>
                            <div class="bg-white p-4 rounded-lg">
                                <h4 class="font-semibold mb-2 text-pink-700">
                                    <i class="fas fa-memory mr-2"></i>空间复杂度
                                </h4>
                                <p class="text-2xl font-mono text-gray-800">O(m × n)</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Backtracking Approach -->
                <div>
                    <h3 class="